<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>按日统计分析</title>
<link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.3.3/themes/default/easyui.css"></link>
<link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.3.3/themes/icon.css"></link>
<script type="text/javascript" src="/static/jquery-easyui-1.3.3/jquery.min.js"></script>
<script type="text/javascript" src="/static/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/static/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="/static/highcharts4/js/highcharts.js"></script>
<script type="text/javascript" src="/static/js/date.js"></script>
<script type="text/javascript">

	$(document).ready(function() {
		
		$("#s_begin").datebox("setValue",genLastWeekDayStr()); // 设置上个月日期
		$("#s_end").datebox("setValue",genTodayStr()); // 设置当前日期
		
		
	});

	function search(){
		$("#dg").datagrid("loadData",{total:0,rows:[]});
		
		var chart=new Highcharts.Chart({
			chart:{
				renderTo:"container",
				type:'column',
				events:{
					load:function(event){
						var begin=$("#s_begin").datebox("getValue");
						var end=$("#s_end").datebox("getValue");
						$.post("/admin/saleList/countSaleByDay",{begin:begin,end:end},function(result){
							var rows=result.rows;
							var xArr=new Array();
							var yArr=new Array();
							for(var i=0;i<rows.length;i++){
								xArr.push(rows[i].date);
								yArr.push(rows[i].amountProfit);
							}
							chart.xAxis[0].categories=xArr;
							chart.series[0].setData(yArr);
							
							var saleTotal=0,costTotal=0,profitTotal=0;
							for(var i=0;i<rows.length;i++){
								var row=rows[i];
								$("#dg").datagrid("appendRow",{
									date:row.date,
									amountSale:row.amountSale,
									amountCost:row.amountCost,
									amountProfit:row.amountProfit
								});
								saleTotal+=row.amountSale;
								costTotal+=row.amountCost;
								profitTotal+=row.amountProfit;
							}
							
							$("#dg").datagrid("appendRow",{
								date:"合计",
								amountSale:saleTotal,
								amountCost:costTotal,
								amountProfit:profitTotal
							});
							
						},"json");
					}
				}
			},
			title:{
				text:'按日统计分析'
			},
			xAxis:{
				title:'日期',
				categories:[
				    'A',
				    'B',
				    'C'
				]
			},
			yAxis:{
				title:{
					text:'销售利润'
				}
			},
			series:[{
				name:'销售利润',
				data:[1,2,3]
			}]
		});
	}
	
	function formatMoney(val,row){
		return "¥"+val;
	}
	
</script>
<body>
	<div style="height: 100px;padding: 10px;border: 0px;">
		<fieldset style="border-color: #E7F0FF">
			<legend>统计设置</legend>
			&nbsp;&nbsp;&nbsp;统计时间：&nbsp;
			<input id="s_begin" class="easyui-datebox" editable=false style="width:100px"/>
			&nbsp;&nbsp;-&nbsp;&nbsp;
			<input id="s_end" class="easyui-datebox" editable=false style="width:100px"/>
			&nbsp;&nbsp;<a href="javascript:search()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
		</fieldset>
	</div>
	
	<div style="padding-left: 10px;padding-right: 10px;border: 0px;height: 350px">
		<div id="container"></div>
	</div>
	
	<div style="padding: 10px;border: 0px;height: 230px">
		<table id="dg" class="easyui-datagrid"
		fitColumns="true"  rownumbers="true" singleSelect="true"
		 fit="true" >
			<thead>
				<th field="date" width="30" align="center">日期</th>
				<th field="amountSale" width="60" align="right" formatter="formatMoney">销售金额</th>
				<th field="amountCost" width="60" align="right" formatter="formatMoney">成本金额</th>
				<th field="amountProfit" width="60" align="right" formatter="formatMoney">盈利金额</th>
			</thead>
		</table>
	</div>
	
</body>
</html>